package com.rh.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.rh.dto.Page;
import com.rh.entity.Attendance;
import com.rh.mapper.AttendanceMapper;
import com.rh.service.AttendanceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.transaction.Transactional;
import java.util.List;

@Service
@Transactional
public class AttendanceServiceImpl implements AttendanceService {
    @Autowired
    private AttendanceMapper attendanceMapper;
    @Override
    public void addMethod(Attendance attendance) {
        attendanceMapper.addMethod(attendance);
    }

    @Override
    public void deleteMethod(Integer attendanceId) {
        attendanceMapper.deleteMethod(attendanceId);
    }

    @Override
    public void updateMethod(Attendance attendance) {
        attendanceMapper.updateMethod(attendance);
    }

    @Override
    public Page getAttendancePage(Integer pageNo, Integer pageSize) {
        Page page=new Page();
        PageHelper.startPage(pageNo,pageSize);
        List<Attendance> methodAll = attendanceMapper.getMethodAll();
        PageInfo<Attendance>info=new PageInfo<Attendance>(methodAll);
        page.setPageNo(info.getPageNum());
        page.setPageSize(info.getPageSize());
        page.setPageCount(info.getPages());
        page.setHasPre(info.isHasPreviousPage());
        page.setHasNext(info.isHasNextPage());
        page.setCount(info.getTotal());
        page.setPage(info.getList());
        return page;
    }

    @Override
    public Attendance getMethodAllById(Integer attendanceId) {
        return attendanceMapper.getMethodAllById(attendanceId);
    }
}
